package com.summer.user.service.impl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

public class MySavedRequestAwareAuthenticationSuccessHandler extends
		SavedRequestAwareAuthenticationSuccessHandler {
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication exception) throws ServletException, IOException{
		String loginType = (String)request.getSession().getAttribute("loginType");
		if(loginType!=null&&loginType.equals("quick")){
			String goBack = (String)request.getSession().getAttribute("goBack");
			if(goBack!=null&&!goBack.equals("")){
				setDefaultTargetUrl(goBack);
				request.getSession().setAttribute("goBack", "/");
			}else{
				setDefaultTargetUrl("/");
			}
		}else{
			setDefaultTargetUrl("/");
		}
		
		super.onAuthenticationSuccess(request, response, exception);
	}
	
}
